package com.dao.impl;

import java.util.List;

import com.dao.SubTypeDao;
import com.model.SubType;

public class SubTypeDaoImpl extends BaseDao implements SubTypeDao {

	public int insert(SubType st) {
		String sql = "insert into tb_subType (superType,typename) values(?,?)";
		Object[] params = { st.getSuperType(), st.getTypeName() };
		return super.excecuteUpdate(sql, params);
	}

	@Override
	public List<SubType> querySubTypesBySuperId(Integer superId) {
		String sql="select * from tb_subType where superType=?";
		Object[] params={superId};
		return super.getEntityList(sql, params, SubType.class);
	}

	@Override
	public List<SubType> querAllSubTypes() {
		String sql="SELECT t1.id,t1.superType,t1.typeName,t2.typeName AS superTypeName FROM tb_subType t1 INNER JOIN tb_supertype t2 ON t1.superType=t2.id";
		return super.getEntityList(sql, null, SubType.class);
	}

	@Override
	public List<SubType> querySubTypesBySuperIds(String superTypeId) {
		String sql="select * from tb_subType where superType in (?)";
		Object[] params={superTypeId};
		return super.getEntityList(sql, params, SubType.class);
	}

	@Override
	public SubType querySubTypeByName(String typename) {
		String sql="SELECT t1.id,t1.superType,t1.typeName,t2.typeName AS superTypeName FROM tb_subType t1 INNER JOIN tb_supertype t2 ON t1.superType=t2.id where t1.typeName=?";
		Object[] params={typename};
		return super.getOneEntity(sql,params,SubType.class);
	}

	@Override
	public int deleteSubTypeByIds(String subTypeId) {
		String sql="delete from tb_subType where id in (?)";
		Object[] params={subTypeId};
		return super.excecuteUpdate(sql, params);
	}
	

}
